home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2003 December / The Sunday Times - The Month 2003-12.iso / mac / The Month DEC 03 / engine / modules / fader.swf / scripts / frame_1 / DoAction.as
Text File  |  2003-11-10  |  5KB  |  196 lines

  1. function init()
  2. {
  3.    trace("fader.init() : strPathPrefix=" + strPathPrefix);
  4.    strPath = Tardis.ASSETS_FOLDER + "images/" + Tardis.ActiveSection.id + "/";
  5.    var i = 0;
  6.    while(i < nodeData.childNodes.length)
  7.    {
  8.       var mc = this.createEmptyMovieClip("mImage_" + i,10 + i);
  9.       mc.imagePath = nodeData.childNodes[i].getText();
  10.       mc.origDepth = 10 + i;
  11.       mc.id = i;
  12.       mc.loadImage = function()
  13.       {
  14.          trace("fader." + this._name + ".loadImage() : " + (this._parent.strPathPrefix + this._parent.strPath + this.imagePath));
  15.          this.createEmptyMovieClip("mImage",2);
  16.          this.mImage.loadMovie(this._parent.strPathPrefix + this._parent.strPath + this.imagePath);
  17.          this.onEnterFrame = function()
  18.          {
  19.             if(this.mImage._height > 0)
  20.             {
  21.                this.isImageLoaded = 1;
  22.                delete this.onEnterFrame;
  23.                this.onImageLoaded();
  24.             }
  25.          };
  26.       };
  27.       mc.fadeIn = function()
  28.       {
  29.          if(!this.isImageLoaded)
  30.          {
  31.             this.loadImage();
  32.          }
  33.          this._alpha = 0;
  34.          this._visible = 1;
  35.          this.swapDepths(100);
  36.          this._parent.fading = this;
  37.          this.onEnterFrame = function()
  38.          {
  39.             this._alpha += 2;
  40.             if(this._alpha >= 100)
  41.             {
  42.                this._alpha = 100;
  43.                this.swapDepths(this.origDepth);
  44.                this.onEnterFrame = null;
  45.                this._parent.setCurrentImage(this.id);
  46.                this._parent.onFadeComplete();
  47.             }
  48.          };
  49.       };
  50.       mc.showNow = function()
  51.       {
  52.          delete this.onEnterFrame;
  53.          if(!this.isImageLoaded)
  54.          {
  55.             this.loadImage();
  56.          }
  57.          this._alpha = 100;
  58.          this._visible = 1;
  59.          this._parent.setCurrentImage(this.id);
  60.       };
  61.       mc.hideNow = function()
  62.       {
  63.          delete this.onEnterFrame;
  64.          this._alpha = 0;
  65.          this._visible = 0;
  66.       };
  67.       arrImages.push(mc);
  68.       i++;
  69.    }
  70.    fading = paused = 0;
  71.    if(arrImages.length > 1 && nodeData.attributes.controls == "true")
  72.    {
  73.       mImage_0.onImageLoaded = function()
  74.       {
  75.          var mc = attachMovie("clp_controls","mc_controls",400);
  76.          mc._x = mImage_0._width - (mc._width - 12) - 10;
  77.          mc._y = mImage_0._height - (mc._height - 11) - 10;
  78.       };
  79.    }
  80.    mImage_0.showNow();
  81.    if(arrImages.length > 1)
  82.    {
  83.       delay();
  84.    }
  85.    onComplete();
  86. }
  87. trace("fader frame 1");
  88. depth = 0;
  89. var strPathPrefix;
  90. var nmDelay = 4000;
  91. var arrImages = [];
  92. var strPath;
  93. this.onUnload = function()
  94. {
  95.    clearInterval(delayIntervalID);
  96. };
  97. onDelayComplete = function()
  98. {
  99.    trace("fader.onDelayComplete() " + delayIntervalID);
  100.    clearInterval(delayIntervalID);
  101.    delayIntervalID = null;
  102.    if(paused != 1)
  103.    {
  104.       nextImage.fadeIn();
  105.    }
  106. };
  107. onFadeComplete = function()
  108. {
  109.    trace("fader.onFadeComplete()");
  110.    prevImage.hideNow();
  111.    if(paused != 1)
  112.    {
  113.       delay();
  114.    }
  115. };
  116. delay = function()
  117. {
  118.    trace("fader.delay()");
  119.    clearInterval(delayIntervalID);
  120.    delayIntervalID = setInterval(this,"onDelayComplete",nmDelay);
  121. };
  122. skipPrev = function()
  123. {
  124.    if(delayIntervalID != null)
  125.    {
  126.       clearInterval(delayIntervalID);
  127.       delayIntervalID = null;
  128.    }
  129.    if(fading)
  130.    {
  131.       currImage.showNow();
  132.       nextImage.hideNow();
  133.       fading = 0;
  134.    }
  135.    else
  136.    {
  137.       currImage.hideNow();
  138.       prevImage.showNow();
  139.    }
  140.    delay();
  141. };
  142. skipNext = function()
  143. {
  144.    if(delayIntervalID != null)
  145.    {
  146.       clearInterval(delayIntervalID);
  147.       delayIntervalID = null;
  148.    }
  149.    if(fading)
  150.    {
  151.       fading = 0;
  152.    }
  153.    currImage.hideNow();
  154.    nextImage.showNow();
  155.    delay();
  156. };
  157. pause = function()
  158. {
  159.    trace("fader.pause()");
  160.    clearInterval(delayIntervalID);
  161.    delayIntervalID = null;
  162.    if(paused == 1)
  163.    {
  164.       paused = 0;
  165.       if(!fading)
  166.       {
  167.          onDelayComplete();
  168.       }
  169.    }
  170.    else
  171.    {
  172.       paused = 1;
  173.    }
  174. };
  175. setCurrentImage = function(id)
  176. {
  177.    trace("fader.setCurrentImage(" + id + ")");
  178.    this.currImage = this["mImage_" + id];
  179.    if(id == 0)
  180.    {
  181.       this.prevImage = this["mImage_" + (arrImages.length - 1)];
  182.    }
  183.    else
  184.    {
  185.       this.prevImage = this["mImage_" + (id - 1)];
  186.    }
  187.    if(id == arrImages.length - 1)
  188.    {
  189.       this.nextImage = mImage_0;
  190.    }
  191.    else
  192.    {
  193.       this.nextImage = this["mImage_" + (id + 1)];
  194.    }
  195. };
  196.